from itertools import islice, chain


def take(iterable, n):
    return list(islice(iterable, n))


def generate_batch(items, batch_size=500):
    c = chain(items)
    while True:
        batch = take(c, batch_size)
        if not batch:
            break
        yield batch
